﻿using MediatR;
using T.Vehicleservice.API.Application.Command.AccidentRecordCommand;
using T.Vehicleservice.Repository.Interface;

namespace T.Vehicleservice.API.Application.CommandHandlers.AccidentRecordHandler
{
    public class AccidentRecordBatchDelCommandHandler : IRequestHandler<AccidentRecordBatchDelCommand, int>
    {
        private readonly IAccidentRecordRepository _repository;
        public AccidentRecordBatchDelCommandHandler(IAccidentRecordRepository repository)
        {
            _repository = repository;
        }

        public async Task<int> Handle(AccidentRecordBatchDelCommand request, CancellationToken cancellationToken)
        {
            var list = (await _repository.GetAllAsync());
            var alist=list.Where(x=>request.AccidentId.Contains(x.AccidentId.ToString())).ToList();
            foreach (var item in alist)
            {
                item.IsDeleted = true;
            }
            return await _repository.UpdateRange(alist);
        }
    }
}
